<!--
描述：题库排重处理组件
开发人：fwb
开发日期：2017年8月22日
-->
<template lang="pug">
    keep-alive(v-if="pageShow")
        kalix-table(bizKey="questionsRepeated" title='题库排重信息列表' v-bind:targetURL="targetURL"
        v-bind:bizSearch="'RepeatedSearch'" v-bind:toolbarBtnList="toolbarBtnList"
        v-bind:btnList="btnList" v-bind:customTableTool="customTableTool"
        v-bind:isFixedColumn="isFixedColumn" ref="kalixTable")
            template(slot="tableColumnSlot")
                el-table-column(prop="questionTypeName" label="题型" align="center" width="180px")
                el-table-column(prop="subTypeName" label="题型子类" align="center" width="150px")
                el-table-column(prop="firstQuestionId" label="排重试题id" align="center" width="150px")
                el-table-column(prop="firstStem" label="排重试题题干" align="center" width="350px")
                    template(slot-scope="scope")
                        el-popover(trigger="hover" placement="top" width="350")
                            | {{scope.row.firstStem}}
                            div(slot="reference")
                                template(v-if="scope.row.firstStem && scope.row.firstStem.length > 20")
                                    | {{scope.row.firstStem.substr(0, 20)}}...
                                template(v-else)
                                    | {{scope.row.firstStem}}
                el-table-column(prop="secondQuestionId" label="重复试题id" align="center" width="150px")
                el-table-column(prop="secondStem" label="重复试题题干" align="center" width="350px")
                    template(slot-scope="scope")
                        el-popover(trigger="hover" placement="top" width="350")
                            | {{scope.row.secondStem}}
                            div(slot="reference")
                                template(v-if="scope.row.secondStem && scope.row.secondStem.length > 20")
                                    | {{scope.row.secondStem.substr(0, 20)}}...
                                template(v-else)
                                    | {{scope.row.secondStem}}
                el-table-column(prop="similarityDesc" label="相似度" align="center" width="200px")
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import {AllRepeateURL, RepeateURL} from '../../config.toml'
    import {questionRepeatedBtnList} from '../config.js'
    /*import {availableQuestion} from '../../common.js'*/

    export default {
        name: 'kalix-enrolment-questionsrepeated',
        data() {
            return {
                pageShow: false,
                btnList: questionRepeatedBtnList,
                toolbarBtnList: [
                    {id: 'add', isShow: false}
                ],
                targetURL: AllRepeateURL,
                isFixedColumn: true
            }
        },
        components: {},
        created() {
            /*availableQuestion(this.axios, this.$KalixMessage, flag => {
                this.pageShow = flag
            })*/
            this.pageShow = true
        },
        activated() {
            // this.$KalixEventBus.$on(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK, this.onSearchClick)
        },
        deactivated() {
            // this.$KalixEventBus.$off(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK)
        },
        methods: {
            customTableTool(row, btnId, that) {
                switch (btnId) {
                    case 'saveFirstRepeat': {
                        this.onSaveFirstRepeat(row, that)
                        break
                    }
                    case 'deleteFirstRepeat': {
                        this.onDeleteFirstRepeat(row, that)
                        break
                    }
                    case 'deleteSecondRepeat': {
                        this.onDeleteSecondRepeat(row, that)
                        break
                    }
                }
            },
            onSaveFirstRepeat(row, table) {
                let url = RepeateURL.replace('[beans]', row.questionBeans) + '/' + row.firstQuestionId
                this.axios.request({
                    method: 'PUT',
                    url: url,
                    params: {
                        questionId: row.firstQuestionId
                    }
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                    }
                    this.$refs.kalixTable.refresh()
                }).catch(() => {
                })
            },
            onDeleteFirstRepeat(row, table) {
                let url = RepeateURL.replace('[beans]', row.questionBeans) + '/' + row.firstQuestionId
                this.axios.request({
                    method: 'DELETE',
                    url: url,
                    params: {
                        questionId: row.firstQuestionId
                    }
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                    }
                    this.$refs.kalixTable.refresh()
                }).catch(() => {
                })
            },
            onDeleteSecondRepeat(row, table) {
                let url = RepeateURL.replace('[beans]', row.questionBeans) + '/' + row.secondQuestionId
                this.axios.request({
                    method: 'DELETE',
                    url: url,
                    params: {
                        questionId: row.secondQuestionId
                    }
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                    }
                    this.$refs.kalixTable.refresh()
                }).catch(() => {
                })
            }
        }
    }
</script>

<style scoped lang="stylus">
</style>
